<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品管理</title> <#include "/WEB-INF/content/module-index.html">
<script type="text/javascript">
var typeTree=[
	<#list map.typeTree as item>
		{"id":"${item.id}","text":"${item.text}","children":[
			<#list item.children as ite>
				{"id":"${ite.id}","text":"${ite.text}","children":[
					<#list ite.children as it>
						{"id":"${it.id}","text":"${it.text}"}<#if it_has_next>,</#if>
					</#list>
				]}<#if ite_has_next>,</#if>
			</#list>
		]}<#if item_has_next>,</#if>
	</#list>
];
$(function(){
	$("#search").click(function(){
		var name=$("#infoname").val();
		var typeid=$("#typeid").combobox("getValue");
		var leftTime=$("#leftTime").datetimebox("getValue");
		var rightTime=$("#rightTime").datetimebox("getValue");
		$("#grid").datagrid("reload",{"name":name,"typeid":typeid,"leftTime":leftTime,"rightTime":rightTime});		
	});	
  	$("#parent").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
        panelHeight:'auto',
  		data:typeTree,
  		onChange:function(data){
  			$("#typeid").combobox('setValue','');
  			for(var i in typeTree){
  				if(typeTree[i].id==data){
  					$("#typeid").combobox('loadData',typeTree[i].children);
  				}
  			}
  		}
  	});	
	$("#typeid").combobox({
	  		valueField : 'id',
	  		textField : 'text',
	  		editable:false,
	        panelHeight:'auto'
		});
});

function datetypeFormatter(value,rowData,rowIndex){
	if(value=="0"){
		return "按天数";
	}else
		if(value=="1"){
			return "按起止时间";
		}else{
			return "未设置";
		}
}

function typeFormatter(value,rowData,rowIndex){
	if(value==0)
		return "物流配送";
	else
		if(value==1)
			return "终端领取";
		else
			return "未知";
}

function statusFormatter(value,rowData,rowIndex){
	if(value==0){
		return "正常";
	}else	
		return "禁用";
}

function handleFormatter(value,rowData,rowIndex){
	return '<a href="javascript:uploadImg(\''+rowData.tid+'\',\'top\')">上传图片</a>';
}

function uploadImg(objectid,where){
	top.openModule("ad_ticket-images","票卷图片上传","ticket/info/images/index?_id=ticket&objectid="+objectid);
}
</script>
<style>
a.btn-border{
	border: 1px solid #ccc;
}
</style>
</head>
<body>
<body class="easyui-layout">
	<div region="center" style="padding: 5px; background:#eee;">
		<div id="toolbar">
			<input id="infoname" placeholder="票券名称"/>
			票卷类型<input id="parent"><input id="typeid"/>	
			有效起止时间:<input id="leftTime" class="easyui-datetimebox" editable="false"/>至
			<input id="rightTime" class="easyui-datetimebox" editable="false"/>	
			<a id="search" class="easyui-linkbutton" icon="icon-search" style="border: 1px solid #ccc" plain="true">搜索</a><br/><br/>
			<@auth code="product:info:new">
				<a id="new" class="easyui-linkbutton" onclick="javascript:add();" icon="icon-add" style="border: 1px solid #ccc" plain="true">新增</a>
			</@auth>
			<@auth code="product:info:*:edit">
				<a id="edit" class="easyui-linkbutton" onclick="javascript:edit();" icon="icon-edit" style="border: 1px solid #ccc" plain="true">编辑</a>
			</@auth>
		</div>
		<table id="grid" class="easyui-datagrid" url="query" align="center" idField="tid" rownumbers="true" striped="true" fitColumns="true" fit="true" pagination="true" singleSelect="true" toolbar="#toolbar">
			<thead>
				<tr>
					<th field="ttid" width="50">所属分类</th>
					<th field="infoname" width="50">票券名称</th>
<!--					<th field="pid">商品名称</th>
					<th field="datetype" width="50" formatter="datetypeFormatter">有效期类型</th>
					<th field="validdate" width="50">有效期天数</th> -->
 					<th field="begintime" width="50">开始时间</th>
					<th field="endtime" width="50">结束时间</th>
					<th field="tickettype" width="50" formatter="typeFormatter">配送类型</th>
					<th field="denomination" width="50">面额</th>
					<th field="infointro" width="50">票券描述</th>
					<th field="status" width="50" formatter="statusFormatter">状态</th>
					<th field="createtime" width="50">创建时间</th>
					<th field="creator" width="50">创建者</th>
					<@auth code="product:info:images:index">
					<th field="handle" width="10" formatter="handleFormatter">操作</th>
					</@auth>											
				</tr>
			</thead>
		</table>
	</div>
</body>
</body>

</html>